package org.spring.springboot.service.impl;

import org.spring.springboot.dao.MenuDao;
import org.spring.springboot.domain.AdminMenu;
import org.spring.springboot.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 菜单业务逻辑实现类
 *
 * Created by 赵新国 on 07/02/2017.
 */
@Service
public class MenuServiceImpl implements MenuService {

    @Autowired
    private MenuDao menuDao;

    /**
     * 用户拥有的菜单
     *
     * @param userId
     * @return
     */
    @Override
    public List<AdminMenu> getMenuList(Short userId) {
        return menuDao.getMenuListByUserId(userId, null);
    }

    /**
     * 获取所有菜单
     *
     * @return
     */
    @Override
    public List<AdminMenu> selectAllMenu(Short pid) {
        return menuDao.selectAllMenu(pid);
    }

    /**
     * 查询菜单
     *
     * @param menuId
     * @return
     */
    @Override
    public AdminMenu findAdminMenu(Short menuId) {
        return menuDao.selectByPrimaryKey(menuId);
    }

    /**
     * 保存菜单
     *
     * @param adminMenu
     */
    @Override
    public void saveMenu(AdminMenu adminMenu) {
        if (adminMenu.getMenuId() != null) {
            menuDao.updateByPrimaryKeySelective(adminMenu);
        } else {
            menuDao.insertSelective(adminMenu);
        }
    }

    /**
     * 删除菜单
     *
     * @param menuId
     */
    @Override
    public void deleteMenu(Short menuId) {
        menuDao.deleteByPrimaryKey(menuId);
    }

}
